package team.seekers.hula.course.resource.exam.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.auth.service.MindUtils;
import team.seekers.hula.course.resource.exam.entity.dto.ExamDTO;
import team.seekers.hula.course.resource.exam.entity.dto.ExamPageListReqDTO;
import team.seekers.hula.course.resource.exam.entity.vo.ExamInfoVO;
import team.seekers.hula.course.resource.exam.entity.vo.ExamListVO;
import team.seekers.hula.course.resource.exam.entity.vo.ExamPageListVO;
import team.seekers.hula.course.resource.exam.service.ExamManageService;

import java.util.List;


@Controller
@ApiResponseBody
@RequestMapping("/manage/exam")
public class ExamManageController {

    @Autowired
    private ExamManageService examManageService;

    /**
     * 新增测试
     */
    @PostMapping("/create")
    public void create(@RequestBody ExamDTO examDTO) {
        examDTO.setUserId(MindUtils.getUserId());
        examManageService.save(examDTO);
    }

    /**
     * 更新测试
     */
    @PostMapping("/update")
    public void update(@RequestBody ExamDTO examDTO) {
        examManageService.update(examDTO);
    }

    @GetMapping("/info")
    public ExamInfoVO info(@RequestParam String examId) {
        return examManageService.getInfoVO(examId);
    }

    /**
     * 删除测试
     */
    @GetMapping("/delete")
    public void delete(@RequestParam String examId) {
        examManageService.delete(examId);
    }


    @GetMapping("/page")
    public PageResult<ExamPageListVO> page(ExamPageListReqDTO reqDTO) {
        return examManageService.page(reqDTO);
    }

    @GetMapping("/list")
    public List<ExamListVO> list(@RequestParam String title) {
        return examManageService.list(title);
    }


}
